<?php
/**********************
**actions.php
**Date Created: 4/13/2009
**Copyright 2009 Tomorrow Tech Industries
**Contact: RPITomorrowTech@gmail.com
**********************/

/*
This file should not be aware of the communication technique (ie XML-RPC)

All functions return a map
First value is the return code
Next values are returned values
Ex:
	<?php
	function equations($a, $b, $c, $d, $x, $y) 
	{
		return array($a+$b, $c+$d, $x-$y);
	}
	
	list($result1, $result2, $result3) = equations(3,2,1,2,3,4);
	print "result1 = $result1, result2 = $result2, result3 = $result3";
	?>
*/

require_once("shared/errors.inc");

//Fully off
define("TT_POWER_OFF",	0);
//Fully on
define("TT_POWER_ON",	100);
//Unknown
define("TT_POWER_UNKNOWN",	TT_POWER_ON + 1);

//define("TT_UNSUPPORTED",	(-1));

class Intellistrip
{
	//Current power level
	var $powerLevel;

	function Intellistrip()
	{
		//off by default?
		$this->powerLevel = TT_POWER_UNKNOWN;
	}		

	/********************
	Device power
	********************/
	/********************
	Set device power
	Input
		password: the Intellistrip's access password
		portID: portID of plug to access
		powerLevel: percentage of power to put out
	********************/
	function setPortPower($password, $portID, $powerLevel)
	{
		return array(TT_UNSUPPORTED);
	}

	/*******************
	Get device power
	Input
		password: the Intellistrip's access password
		portID: portID of plug to access
	Output
		rc: return code
		powerLevel: power level
	*******************/
	function getPortPower($password, $portID, &$powerLevel)
	{
		return array(TT_UNSUPPORTED, -1);
	}

	/********************
	Misc
	********************/
	/********************
	Query device information
	Note this is NOT password protected
	Input
		password: the Intellistrip's access password
	Output
		rc: return code
		vendorName: vendor supplied name.
		modelNumber: a number unique with respect to a vendor name to identify 
			different products 
		serialNumber: a number unique to an individual device when combined
			with the vendor name and model number
		numberPorts: the number of ports availible on the device
		state: is the power strip on and availible?
	********************/
	function getIntellistripInformation()
	{
		return array(TT_UNSUPPORTED, '', '', '', 0, 0);
	}
}


echo "
<HTML>
<BODY>
";

$strip = new Intellistrip();

$strip->setPortPower('', 1, 45) >= 0 or die("Set power level failed");
$strip->getPortPower('', 1, $powerLevel) >= 0 or die("Get power level failed");


echo "Power level: " . $powerLevel;

echo "
</BODY>
</HTML>
";

?>

